﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
//方法一：
using System.Net.Mail;

/*方法二：
using System.Web.Mail;
 * */


namespace JKDD.Doctor
{
    public partial class doctorGetPass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string doctorID = txtDoctorID.Text.ToString();
            if (doctorID.Trim().Length > 0)
            {
                string sql = "select SPASS,SEMAIL from TB_DOCTOR_INFO where SREGISTERID=" + doctorID;
                //try
                //{
                    DataTable dt = operateDB.GetDataTable(sql);
                    if (dt.Rows.Count > 0)
                    {
                        string pass = dt.Rows[0]["SPASS"].ToString();
                        string email = dt.Rows[0]["SEMAIL"].ToString();
                        //方法一：
                        MailMessage mail = new MailMessage("zhou@jkdd.net", email, "取回密码", "您的密码是：" + pass);
                        SmtpClient smtp = new SmtpClient();
                        smtp.Host = "mail.jkdd.net";
                        smtp.Credentials = new System.Net.NetworkCredential("zhou@jkdd.net", "90153476");
                        smtp.Send(mail);
                        
                        /*方法二：
                        MailMessage mail = new MailMessage();
                        mail.To = email;
                        mail.From = "javascriptjack@gmail.com";
                        mail.Subject = "取回密码";
                        mail.Body = "您的密码是：" + pass;
                        mail.BodyFormat = MailFormat.Html;//设置为HTML格式 
                        mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2);
                        mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendemailaddress", email);
                        mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpaccountname", "javascriptjack@gmail.com");
                        //设置为需要用户验证
                        mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                        //设置验证用户名 
                        mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","javascriptjack");
                        //设置验证密码 
                        mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "912842011");

                        System.Web.Mail.SmtpMail.SmtpServer = "smtp.google.com";
                        System.Web.Mail.SmtpMail.Send(mail);
                        */

                        lblMessage.Text = "请到登陆你的密码保护邮箱取回你的密码。";
                    }
                    else
                    {
                        lblMessage.Text = "对不起，你所输入的网号不存在！";
                    }
                //}
                //catch (Exception ex)
                //{
                    //lblMessage.Text = "对不起，服务器正忙，请稍后再取回密码！";
                //}
            }
            else
            {
                lblMessage.Text = "请输入网号！";
            }
        }
    }
}
